import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    // alwaysShow: true,
    // meta: { title: '首页', icon: 'dashboard', affix: true },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: {
        title: '首页',
        icon: 'dashboard',
        affix: true
      }
    }]
  },
  {
    path: '/error',
    component: Layout,
    // redirect: 'noRedirect',
    name: 'ErrorPages',
    hidden:true,
    meta: {
      title: 'Error Pages',
      icon: '404'
    },
    children: [{
        path: '401',
        component: () => import('@/views/error-page/401'),
        name: 'Page401',
        meta: {
          title: '401',
          noCache: true
        }
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404'),
        name: 'Page404',
        meta: {
          title: '404',
          noCache: true
        }
      }
    ]
  },
  // {
  //   path: '/documentation',
  //   component: Layout,
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/documentation/index'),
  //       name: 'Documentation',
  //       meta: { title: 'Documentation', icon: 'documentation', affix: true },

  //     }
  //   ]
  // },
  // {
  //   path: '/guide',
  //   component: Layout,
  //   redirect: '/guide/index',
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/guide/index'),
  //       name: 'Guide',
  //       meta: { title: 'Guide', icon: 'guide', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/profile',
  //   component: Layout,
  //   alwaysShow: true,
  //   redirect: '/profile/index',
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/profile/index'),
  //       name: 'Profile------',
  //       meta: { title: 'Profile', icon: 'user', noCache: true }
  //     }
  //   ]
  // }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 * 所有的 有实际页面的name 都是上级name的拼接！！！！！！！！！确保唯一！！！权限验证用的name
 */
export const asyncRoutes = [{
    path: '/jiesuan',
    component: Layout,
    redirect: '/jiesuan/item',
    // alwaysShow: true, // will always show the root menu
    name: 'jiesuan',
    meta: {
      title: '结算管理',
      icon: 'el-icon-menu'
    },
    children: [{
        path: 'item',
        component: () => import('@/views/jiesuan/item/index'), //二级目录都需要 router-view
        name: 'item',
        redirect: '/jiesuan/item/nojiesuan',
        // alwaysShow: true,
        meta: {
          title: '项目管理'
        },
        children: [{
            path: 'peihe',
            component: () => import('@/views/jiesuan/item/peihe'),
            name: 'item_peihe', //上级目录的拼接
            meta: {
              title: '我配合项目'
            },
          },
          {
            path: 'fuze',
            component: () => import('@/views/jiesuan/item/fuze'),
            name: 'item_fuze', //上级目录的拼接
            meta: {
              title: '我负责项目'
            },
          },
          {
            path: 'all',
            component: () => import('@/views/jiesuan/item/all'),
            name: 'item_all', //上级目录的拼接
            meta: {
              title: '全部项目'
            },
          },
          {
            path: 'hook',
            component: () => import('@/views/jiesuan/item/hook'),
            name: 'item_hook', //上级目录的拼接
            hidden: true,
            meta: {
              title: '结算'
            },
          },
        ]
      },
      {
        path: 'contract',
        component: () => import('@/views/jiesuan/contract/index'),
        name: 'contract',
        // alwaysShow: true,
        meta: {
          title: '合同管理'
        },
        children: [{
            path: 'peihe_list',
            component: () => import('@/views/jiesuan/contract/peihe_list'),
            name: 'contract_peihe_list',
            meta: {
              title: '我配合合同'
            }
          },
          {
            path: 'fuze_list',
            component: () => import('@/views/jiesuan/contract/fuze_list'),
            name: 'contract_fuze_list',
            meta: {
              title: '我负责合同'
            }
          },
          {
            path: 'add_list',
            component: () => import('@/views/jiesuan/contract/add_list'),
            name: 'contract_add_list',
            meta: {
              title: '添加合同列表'
            }
          },
          {
            path: 'add',
            component: () => import('@/views/jiesuan/contract/add'),
            name: 'contract_add',
            hidden: true,
            meta: {
              title: '添加合同'
            }
          },
          {
            path: 'edit',
            component: () => import('@/views/jiesuan/contract/edit'),
            name: 'contract_edit',
            hidden: true,
            meta: {
              title: '编辑合同'
            }
          },
          {
            path: 'all',
            component: () => import('@/views/jiesuan/contract/all'),
            name: 'contract_all',
            meta: {
              title: '全部合同'
            }
          },
          {
            path: 'uncheck',
            component: () => import('@/views/jiesuan/contract/uncheck'),
            name: 'contract_uncheck',
            meta: {
              title: '待审核合同'
            }
          },
          {
            path: 'overtime',
            component: () => import('@/views/jiesuan/contract/overtime'),
            name: 'contract_overtime',
            meta: {
              title: '超期预警'
            }
          },
          {
            path: 'void',
            component: () => import('@/views/jiesuan/contract/void'),
            name: 'contract_void',
            meta: {
              title: '作废合同'
            }
          },
          {
            path: 'detail',
            component: () => import('@/views/jiesuan/contract/detail'),
            name: 'contract_detail',
            hidden: true,
            meta: {
              title: '合同详情'
            }
          }
        ]
      },
      {
        path: 'jiesuan_list',
        component: () => import('@/views/jiesuan/jiesuan_list/index'),
        name: 'jiesuan_list',
        // alwaysShow: true,
        meta: {
          title: '结算列表'
        },
        children: [{
            path: 'peihe_jiesuan',
            component: () => import('@/views/jiesuan/jiesuan_list/peihe_jiesuan'),
            name: 'jiesuan_list_peihe_jiesuan',
            meta: {
              title: '我配合结算单'
            }
          },
          {
            path: 'fuze_jiesuan',
            component: () => import('@/views/jiesuan/jiesuan_list/fuze_jiesuan'),
            name: 'jiesuan_list_fuze_jiesuan',
            meta: {
              title: '我负责结算单'
            }
          },
          {
            path: 'all_jiesuan',
            component: () => import('@/views/jiesuan/jiesuan_list/all_jiesuan'),
            name: 'jiesuan_list_all_jiesuan',
            meta: {
              title: '全部结算单'
            }
          },
          {
            path: 'detail',
            component: () => import('@/views/jiesuan/jiesuan_list/detail'),
            name: 'jiesuan_list_detail',
            hidden: true,
            meta: {
              title: '结算单详情'
            }
          },
          {
            path: 'edit',
            component: () => import('@/views/jiesuan/jiesuan_list/edit'),
            name: 'jiesuan_list_edit',
            hidden: true,
            meta: {
              title: '修改结算单'
            }
          },
          {
            path: 'overtime',
            component: () => import('@/views/jiesuan/jiesuan_list/overtime'),
            name: 'jiesuan_list_overtime',
            meta: {
              title: '超期预警'
            }
          }
        ]
      }
    ]
  },
  {
    path: '/kaipiao',
    component: Layout,
    redirect: '/kaipiao/kaipiao_not',
    alwaysShow: true, // will always show the root menu
    name: 'kaipiao',
    meta: {
      title: '开票管理',
      icon: 'el-icon-s-check'
    },
    children: [{
        path: 'kaipiao_not',
        component: () => import('@/views/kaipiao/kaipiao_not'),
        name: 'kaipiao_not',
        meta: {
          title: '待开票列表'
        }
      },
      {
        path: 'kaipiao_has',
        component: () => import('@/views/kaipiao/kaipiao_has'),
        name: 'kaipiao_has',
        meta: {
          title: '已开票列表'
        },
      },
      {
        path: 'fapiao_list',
        component: () => import('@/views/kaipiao/fapiao_list'),
        name: 'fapiao_list',
        meta: {
          title: '发票列表'
        },
      },
      {
        path: 'fapiao_list_all',
        component: () => import('@/views/kaipiao/fapiao_list_all'),
        name: 'fapiao_list_all',
        hidden:true,
        meta: {
          title: '全部发票'
        },
      },
      {
        path: 'kaipiao_detail',
        component: () => import('@/views/kaipiao/kaipiao_detail'),
        name: 'kaipiao_detail',
        hidden: true,
        meta: {
          title: '开票详情'
        },
      },
      {
        path: 'jiesuan_detail',
        component: () => import('@/views/jiesuan/jiesuan_list/detail'),
        name: 'jiesuan_list_detail',
        hidden: true,
        meta: {
          title: '结算单详情-财务'
        }
      },
      {
        path: 'hetong_detail',
        component: () => import('@/views/jiesuan/contract/detail'),
        name: 'contract_detail',
        hidden: true,
        meta: {
          title: '合同详情-财务'
        }
      }
    ]
  },
  {
    path: '/huikuan',
    component: Layout,
    redirect: '/huikuan/huikuan_not',
    alwaysShow: true, // will always show the root menu
    name: 'huikuan',
    meta: {
      title: '回款管理',
      icon: 'el-icon-goods'
    },
    children: [{
        path: 'huikuan_not',
        component: () => import('@/views/huikuan/huikuan_not'),
        name: 'huikuan_not',
        hidden: true,
        meta: {
          title: '全部未回款列表'
        }
      },
      {
        path: 'huikuan_has',
        component: () => import('@/views/huikuan/huikuan_has'),
        name: 'huikuan_has',
        hidden: true,
        meta: {
          title: '全部已回款列表'
        },
      },
      {
        path: 'no_huikuan_fapiao',
        component: () => import('@/views/huikuan/no_huikuan_fapiao'),
        name: 'no_huikuan_fapiao',
        meta: {
          title: '未回款发票'
        },
      },
      {
        path: 'has_huikuan_fapiao',
        component: () => import('@/views/huikuan/has_huikuan_fapiao'),
        name: 'has_huikuan_fapiao',
        meta: {
          title: '已回款发票'
        },
      },
      {
        path: 'huikuan_list',
        component: () => import('@/views/huikuan/huikuan_list'),
        name: 'huikuan_list',
        meta: {
          title: '回款登记列表'
        },
      },
      {
        path: 'huikuan_list_all',
        component: () => import('@/views/huikuan/huikuan_list_all'),
        name: 'huikuan_list_all',
        hidden:true,
        meta: {
          title: '全部回款记录'
        },
      },
    ]
  },
  {
    path: '/kaohe',
    component: Layout,
    redirect: '/kaohe/kaohe_rank',
    alwaysShow: true, // will always show the root menu
    name: 'kaohe',
    meta: {
      title: '考核管理',
      icon: 'el-icon-s-order'
    },
    children: [
      {
        path: 'huikuan_rank',
        component: () => import('@/views/kaohe/huikuan_rank'),
        name: 'huikuan_rank',
        meta: {
          title: '回款金额排名'
        }
      },
      {
        path: 'liangxinglv',
        component: () => import('@/views/kaohe/liangxinglv'),
        name: 'liangxinglv',
        meta: {
          title: '良性率'
        }
      },
      {
        path: 'risk_money',
        component: () => import('@/views/kaohe/risk_money'),
        name: 'risk_money',
        meta: {
          title: '风险金'
        }
      },

    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/user_userlist',
    alwaysShow: true, // will always show the root menu
    name: 'user',
    meta: {
      title: '用户管理',
      icon: 'el-icon-user'
    },
    children: [{
        path: 'user_userlist',
        component: () => import('@/views/user/user_userlist'),
        name: 'user_userlist',
        meta: {
          title: '用户列表'
        }
      },
      {
        path: 'user_roles',
        component: () => import('@/views/user/user_roles'),
        name: 'user_roles',
        meta: {
          title: '角色权限'
        },
      }
    ]
  },
  {
    path: '/setup',
    component: Layout,
    redirect: '/setup/setup_userlist',
    alwaysShow: true, // will always show the root menu
    name: 'setup',
    meta: {
      title: '设置',
      icon: 'el-icon-setting'
    },
    children: [{
        path: 'setup_menus',
        component: () => import('@/views/setup/setup_menus'),
        name: 'setup_menus',
        meta: {
          title: '系统菜单'
        },
      },
      {
        path: 'setup_buslist',
        component: () => import('@/views/setup/setup_buslist'),
        name: 'setup_buslist',
        meta: {
          title: '业务类型'
        },
      },
      {
        path: 'setup_notice',
        component: () => import('@/views/setup/setup_notice'),
        name: 'setup_notice',
        meta: {
          title: '通知公告'
        },
      },
      {
        path: 'setup_notice_noauth',
        component: () => import('@/views/setup/setup_notice_noauth'),
        name: 'setup_notice_noauth',
        hidden: true,
        meta: {
          title: '通知公告'
        },
      },
      {
        path: 'setup_diary',
        component: () => import('@/views/setup/setup_diary'),
        name: 'setup_diary',
        meta: {
          title: '工作日记'
        },
      },
      {
        path: 'setup_banner',
        component: () => import('@/views/setup/setup_banner'),
        name: 'setup_banner',
        meta: {
          title: '首页轮播图'
        },
      }
    ]
  },


  //---------------以下暂时没用----------------------

  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Permission',
    meta: {
      title: 'Permission',
      icon: 'lock',
      roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [{
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: 'Page Permission',
          roles: ['admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: 'Directive Permission'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'role',
        component: () => import('@/views/permission/role'),
        name: 'RolePermission',
        meta: {
          title: 'Role Permission',
          roles: ['admin']
        }
      }
    ]
  },

  {
    path: '/icon',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/icons/index'),
      name: 'Icons',
      meta: {
        title: 'Icons',
        icon: 'icon',
        noCache: true
      }
    }]
  },

  /** when your routing map is too long, you can split it into small modules **/
  // componentsRouter,
  // chartsRouter,
  // nestedRouter,
  tableRouter,
  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'Example',
    meta: {
      title: 'Example',
      icon: 'el-icon-s-help'
    },
    children: [{
        path: 'create',
        component: () => import('@/views/example/create'),
        name: 'CreateArticle',
        meta: {
          title: 'Create Article',
          icon: 'edit'
        }
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: {
          title: 'Edit Article',
          noCache: true,
          activeMenu: '/example/list'
        },
        hidden: true
      },
      {
        path: 'list',
        component: () => import('@/views/example/list'),
        name: 'ArticleList',
        meta: {
          title: 'Article List',
          icon: 'list'
        }
      }
    ]
  },

  {
    path: '/tab',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/tab/index'),
      name: 'Tab',
      meta: {
        title: 'Tab',
        icon: 'tab'
      }
    }]
  },

  {
    path: '/error',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ErrorPages',
    meta: {
      title: 'Error Pages',
      icon: '404'
    },
    children: [{
        path: '401',
        component: () => import('@/views/error-page/401'),
        name: 'Page401',
        meta: {
          title: '401',
          noCache: true
        }
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404'),
        name: 'Page404',
        meta: {
          title: '404',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/error-log',
    component: Layout,
    children: [{
      path: 'log',
      component: () => import('@/views/error-log/index'),
      name: 'ErrorLog',
      meta: {
        title: 'Error Log',
        icon: 'bug'
      }
    }]
  },

  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/export-excel',
    name: 'Excel',
    meta: {
      title: 'Excel',
      icon: 'excel'
    },
    children: [{
        path: 'export-excel',
        component: () => import('@/views/excel/export-excel'),
        name: 'ExportExcel',
        meta: {
          title: 'Export Excel'
        }
      },
      {
        path: 'export-selected-excel',
        component: () => import('@/views/excel/select-excel'),
        name: 'SelectExcel',
        meta: {
          title: 'Export Selected'
        }
      },
      {
        path: 'export-merge-header',
        component: () => import('@/views/excel/merge-header'),
        name: 'MergeHeader',
        meta: {
          title: 'Merge Header'
        }
      },
      {
        path: 'upload-excel',
        component: () => import('@/views/excel/upload-excel'),
        name: 'UploadExcel',
        meta: {
          title: 'Upload Excel'
        }
      }
    ]
  },

  {
    path: '/zip',
    component: Layout,
    redirect: '/zip/download',
    alwaysShow: true,
    name: 'Zip',
    meta: {
      title: 'Zip',
      icon: 'zip'
    },
    children: [{
      path: 'download',
      component: () => import('@/views/zip/index'),
      name: 'ExportZip',
      meta: {
        title: 'Export Zip'
      }
    }]
  },

  {
    path: '/pdf',
    component: Layout,
    redirect: '/pdf/index',
    children: [{
      path: 'index',
      component: () => import('@/views/pdf/index'),
      name: 'PDF',
      meta: {
        title: 'PDF',
        icon: 'pdf'
      }
    }]
  },
  {
    path: '/pdf/download',
    component: () => import('@/views/pdf/download'),
    hidden: true
  },

  {
    path: '/theme',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/theme/index'),
      name: 'Theme',
      meta: {
        title: 'Theme',
        icon: 'theme'
      }
    }]
  },

  {
    path: '/clipboard',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/clipboard/index'),
      name: 'ClipboardDemo',
      meta: {
        title: 'Clipboard',
        icon: 'clipboard'
      }
    }]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [{
      path: 'https://github.com/PanJiaChen/vue-element-admin',
      meta: {
        title: 'External Link',
        icon: 'link'
      }
    }]
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
